/*
 * CrossRoadsState.hpp
 *
 *  Created on: 15 jan. 2013
 *      Author: Admin
 */

#ifndef CROSSROADSSTATE_HPP_
#define CROSSROADSSTATE_HPP_

#include "LaneEvent.hpp"
#include "Navigator.hpp"
#include "State.hpp"

class CrossRoadsState : public State {
public:
	CrossRoadsState();
	virtual ~CrossRoadsState();

	/**
	 * Handles incoming events.
	 *
	 * @param the event that should be handled.
	 * @see Event.hpp
	 */

	virtual void handleEvent(Event& event);

	/**
	 * initialises state.
	 * This function is not implemented yet.
	 */
	virtual void startState();

	/**
	 * Returns the state's type.
	 *
	 * @return State::FOLLOWCOLORLANE
	 * @see StateType.hpp
	 */
	virtual StateType getStateType();
private:
	enum Status
	{
		DRIVINGTOWARDSINTERSECTION,
		TAKINGLEFTSIDEEXIT,
		TAKINGRIGHTSIDEEXIT,
		CROSSINGINTERSECTION
	};

	Status status;

//	bool leftTurnPossible, rightTurnPossible;

	void handleLaneEvent(LaneEvent& event);
//	void makeTurnIfPossible();

	void turnLeft();
	void turnRight();
	void crossIntersection();
	void setDirection(Navigator::Direction aDirection);

	bool isDone(LaneEvent& event);

	Navigator::Direction nextDirection;
	bool hasDirection, onCrossRoads;

//	void updatePossibleSideExits();
};

#endif /* CROSSROADSSTATE_HPP_ */
